package com.cqut.forum.service.imp;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.cqut.forum.dao.ModuleDao;
import com.cqut.forum.dao.ModuleInformationDao;
import com.cqut.forum.entity.Module;
import com.cqut.forum.service.ModuleService;
import com.cqut.forum.util.MapKey;

/**
 * 模块service接口实现类
 * @author yangxun
 */
@Component
public class ModuleServiceImp implements ModuleService {
	@Resource
	private ModuleDao moduleDao;
	@Resource
	private ModuleInformationDao informationDao;
	@Override
	public Module getByName(String moduleName) {
		
		return null;
	}

	@Override
	public int getModuleIndex(String moduleName) {
		return moduleDao.getModuleIndex(moduleName);
	}

	/*************get and set method*******************/
	public ModuleDao getModuleDao() {
		return moduleDao;
	}

	public void setModuleDao(ModuleDao moduleDao) {
		this.moduleDao = moduleDao;
	}

	@Override
	public List<Map<String, Object>> loadModuleInfos() {
		List<Map<String, Object>> moduleInfos = informationDao.loadModuleInfos();
		return MapKey.changeMapKey(moduleInfos);
	}

	@Override
	public boolean updateModuleCss(Integer[] moduleIds, String[] csss) {
		for(int i=0;i<moduleIds.length;i++){
			moduleDao.updateModuleCss(moduleIds[i],csss[i]);
		}
		return true;
	}

	@Override
	public List<Map<String, Object>> loadModules() {
		List<Map<String, Object>> modules = moduleDao.loadModules();
		return MapKey.changeMapKey(modules);
	}

	@Override
	public Map<String, Object> loadModuleInfo(String moduleName) {
		Map<String, Object> info = moduleDao.loadModuleInfo(moduleName);
		return MapKey.changeMapKey(info);
	}
}
